package chixing.day20.work5;

import chixing.day20.work4.Location;

//riderId：骑手编号
//riderName：骑手姓名
//isRiderAvailable：是否空闲
//currentOrderCount：当前骑手已接订单数（用于负载均衡）
//riderLocation：骑手当前位置（可用坐标 x,y 表示）
//riderMaxCapacity：最大可同时接单数
public class Rider {
    private int riderId;
    private String riderName;
    private boolean isRiderAvailable;
    private int currentOrderCount;
     private Location riderLocation;
     private int riderMaxCapacity;
     public Rider(){

     }
     public Rider(int riderId, String riderName, boolean isRiderAvailable,
                 Location riderLocation, int riderMaxCapacity) {
         this.riderId = riderId;
         this.riderName = riderName;
         this.isRiderAvailable = isRiderAvailable;
         this.currentOrderCount = 0;
         this.riderLocation = riderLocation;
         this.riderMaxCapacity = riderMaxCapacity;
     }

    public int getRiderId() {
        return riderId;
    }

    public void setRiderId(int riderId) {
        this.riderId = riderId;
    }

    public String getRiderName() {
        return riderName;
    }

    public void setRiderName(String riderName) {
        this.riderName = riderName;
    }

    public boolean isRiderAvailable() {
        return isRiderAvailable;
    }

    public void setRiderAvailable(boolean riderAvailable) {
        isRiderAvailable = riderAvailable;
    }

    public int getCurrentOrderCount() {
        return currentOrderCount;
    }

    public void setCurrentOrderCount(int currentOrderCount) {
        this.currentOrderCount = currentOrderCount;
    }

    public Location getRiderLocation() {
        return riderLocation;
    }

    public void setRiderLocation(Location riderLocation) {
        this.riderLocation = riderLocation;
    }

    public int getRiderMaxCapacity() {
        return riderMaxCapacity;
    }

    public void setRiderMaxCapacity(int riderMaxCapacity) {
        this.riderMaxCapacity = riderMaxCapacity;
    }

    @Override
    public String toString() {
        return "Rider{" +
                "riderId=" + riderId +
                ", riderName='" + riderName + '\'' +
                ", isRiderAvailable=" + isRiderAvailable +
                ", currentOrderCount=" + currentOrderCount +
                ", riderLocation=" + riderLocation +
                ", riderMaxCapacity=" + riderMaxCapacity +
                '}';
    }

    public boolean canAcceptOrder() {
         return isRiderAvailable && currentOrderCount < riderMaxCapacity;
    }

    public void completeOrder() {
         if (currentOrderCount > 0) {
             currentOrderCount--;
             isRiderAvailable = true;
         }
    }
}
